package com.xlhj.boot.webservice.ws.server.config;

import com.xlhj.boot.webservice.ws.api.service.UserInfoService;
import com.xlhj.boot.webservice.ws.server.interceptor.WebServiceAuthInterceptor;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @Author: caijliu
 * @Date: 06/12/2021 11:50
 * @Description TODO
 * @Vsersion: 0.0.1
 */
@Configuration
public class CXFConfig {

    @Autowired
    private Bus bus;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private WebServiceAuthInterceptor interceptor;

    /**
     * 设置WebService访问父路径
     * @return
     */
    @Bean
    public ServletRegistrationBean getRegistrationBean() {
        return new ServletRegistrationBean(new CXFServlet(), "/services/*");
    }

    @Bean
    public Endpoint messageEndPoint() {
        EndpointImpl endpoint = new EndpointImpl(this.bus, this.userInfoService);
        endpoint.publish("/userInfoService");
        endpoint.getInInterceptors().add(this.interceptor);
        return endpoint;
    }
}
